package com.abe.libquick.base.mvp;

import com.abe.libcore.utils.CommonUtils;

import java.util.Locale;

public class BaseLogPresenter<V extends BaseView> extends BasePresenter<V> {
    //监听日志
    protected void onEnd(String o) {
        if (isViewAttached()) {
            getView().onFinish(o);
        } else {
            showViewAttachedError();
        }
    }

    protected boolean onSuccess(Object data) {
        if (isViewAttached()) {
            if (data == null) {
                showViewDataNullError();
            }
            return data != null;
        } else {
            showViewAttachedError();
            return false;
        }
    }

    protected void onFailure(String o) {
        if (isViewAttached()) {
            getView().onFail(o);
        } else {
            showViewAttachedError();
        }
    }

    protected void showViewAttachedError() {
        CommonUtils.INSTANCE.log(String.format(Locale.CHINA, "%s:MVP_PRESENTER_ERROR_ViewAttached", this.getClass().getSimpleName()));
    }

    protected void showViewDataNullError() {
        CommonUtils.INSTANCE.log(String.format(Locale.CHINA, "%s:MVP_PRESENTER_ERROR_DATA_NULL", this.getClass().getSimpleName()));
    }

    protected void showError(String error) {
        CommonUtils.INSTANCE.log(String.format(Locale.CHINA, "%s:%s", this.getClass().getSimpleName(), error));
    }
}